﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZhimeiSoft.Framework.Client.Utils;
using ZhimeiSoft.Framework.Client.Base;
using ZhimeiSoft.CharmManager.Client.App;
using ZhimeiSoft.CharmManager.Client.Manager;
using ZhimeiSoft.CharmManager.Interface;
using ZhimeiSoft.CharmManager.DOL;
using ZhimeiSoft.Framework.Client.Control.DateTimeGrid;
using ZhimeiSoft.Framework.Client.Control;


namespace ZhimeiSoft.CharmManager.Client.Forms.Reservation
{

    public partial class CustomReservationTimeOut : BaseUserControl
    {
        public DBEntityReservation GetReservationInfo {
            get
            {
                if (grdViewScheduleMonthTimeOut.FocusedRowHandle < 0)
                {
                    return null;
                }

                return new DBEntityReservation(grdViewScheduleMonthTimeOut.GetDataRow(grdViewScheduleMonthTimeOut.FocusedRowHandle));
            }
        }

        public EventOnDBClick EventDBClick;

        private DataSet dsReservationTimeout = new DataSet();

        public CustomReservationTimeOut()
        {
            InitializeComponent();
        }

        public void InitQueryReservation(DataSet dsReservation)
        {
            if (dsReservation == null)
            {
                return;
            }
            dsReservationTimeout = dsReservation.Copy();
            grdCtrlScheduleMonthTimeOut.DataSource = dsReservationTimeout.Tables[0];
        }

        private void grdViewScheduleMonth_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            if (e.RowHandle < 0)
            {
                return;
            }
            if (e.Column.FieldName.Equals(DBEntityReservation.FieldName.RSTATE))
            {
                if (e.CellValue == null || e.CellValue.ToString() == string.Empty)
                    return;

                string displayText = DBEntityReservation.ENUM_RSTATE.EnumStrToChineseStr(e.CellValue.ToString());
                if (displayText.Equals(string.Empty))
                    return;
                e.DisplayText = displayText;
            }
        }

        private void grdViewScheduleMonthTimeOut_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            int ihandle = grdViewScheduleMonthTimeOut.FocusedRowHandle;
            if (ihandle < 0)
                return;

            string error = string.Empty;
            DataRow drReservation = grdViewScheduleMonthTimeOut.GetDataRow(ihandle);
            int reservationID = Convert.ToInt16(drReservation[DBEntityReservation.FieldName.RESERVATIONID]);
            DataSet dsReservationDetail = new DataSet();
            if (!BussinessProxyManager.Instance.QueryReservationServiceItemDetail(reservationID, out dsReservationDetail, out error))
            {
                MsgBox.MsgInfo("获取预约明细数据出现错误：" + error);
                return;
            }
            grdReservationDetail.DataSource = dsReservationDetail.Tables[0];
        }

        private void grdViewScheduleMonthTimeOut_DoubleClick(object sender, EventArgs e)
        {
            if (EventDBClick != null)
            {
                DBEntityReservation reservation = GetReservationInfo;
                if (reservation == null)
                    return;
                EventDBClick(grdViewScheduleMonthTimeOut.GetDataRow(grdViewScheduleMonthTimeOut.FocusedRowHandle));
            }
            
        }

    }
}
